/**
 * 武器选择tab
 */
class WeaponTabBarItem extends BaseComp{
    private lb_1:eui.Label;
    private lb_2:eui.Label;
    private lb_3:eui.Label;
    private img_show1:eui.Image;
    private img_show2:eui.Image;
    private img_show3:eui.Image;
    private group_1:eui.Group;
    private group_2:eui.Group;
    private group_3:eui.Group;

    private curSelectTabIndex:number;
    
    constructor()
    {
        super('weaponTabBar');
    }

    public init()
    {
        this.touchHandle([1]);
    }

    protected addEvent()
    {
        for(let i=1;i<4;i++)
        {
            let group:eui.Group = this['group_'+i] as eui.Group;
            group.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchHandle.bind(this, [i]), this);
        }
    }

    protected touchHandle(data)
    {
        let index = data[0];
        if(index == this.curSelectTabIndex)return;
        this.updateSelf(index)
        GameUtil.dispatchEvent(EventConst.CHANGE_PAGE, {index : index});
    }

    protected updateSelf(index)
    {
        if(this.curSelectTabIndex)
        {
            this['img_show'+this.curSelectTabIndex].visible = false;
            let Label = this['lb_'+this.curSelectTabIndex] as eui.Label;
            Label.textColor = 0x0074C8;
        }
        this.curSelectTabIndex = index;
        this['img_show'+index].visible = true;
        let Label = this['lb_'+this.curSelectTabIndex] as eui.Label;
        Label.textColor = 0xffffff;
    }

    protected removeEvent()
    {
        for(let i=1;i<4;i++)
        {
            let group:eui.Group = this['group_'+i] as eui.Group;
            group.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchHandle.bind(this, [i]), this);
        }
    }

    public clear()
    {
        super.clear();
    }
}

window['WeaponTabBarItem'] = WeaponTabBarItem;